import { defineStore, acceptHMRUpdate } from "pinia";
import { activityList } from "@/api/common";
export const activityAppStore = defineStore({
  id: "activity",
  state: () => ({
    activityInfo: {} as any,
    productActList: [] as any[] // 关联产品的活动
  }),
  actions: {
    getActivityInfo() {
      if (this.productActList.length) {
        this.productActList = [];
      }
      if (this.activityInfo.id) {
        this.activityInfo = {};
      }
      activityList().then((res) => {
        const { list = [] } = res.data || {};
        const data = list.find((it: any) => it.act_fixed_id === "10003");
        if (data) {
          this.activityInfo = data;
        }
        const productActList = list.filter(
          (it: any) => ["10004"].includes(it.act_fixed_id) && it.product_ids.length
        );
        if (productActList.length) {
          this.productActList = productActList;
        }
      });
    }
  }
});
if (import.meta.hot) {
  import.meta.hot.accept(acceptHMRUpdate(activityAppStore, import.meta.hot));
}
